<template>
	<view class="head">
		<view class="head-con">
			<view class="left-title">
				<view class="left-title-text">
					<text>消息</text>
				</view>
				<view class="title-loading">
					<message-loading :isShowLoading="loadingning"></message-loading>
				</view>
			</view>
			<view class="right">
				<view class="right-close" @click="closeMessage">
					<image :src="require('@/static/img/main/message/04.svg')"></image>
				</view>
				<view class="right-tool" @click="showTool">
					<image :src="toolImg"></image>
				</view>
			</view>
		</view>
		<view class="head-con-zw"></view>
		<!-- 背景 -->
		<view class="tool-con-bg" v-if="isShowTool" @click="closeShowTool">
			<!-- 工具栏 -->
			<view class="tool-con" v-if="isShowTool">
				<view class="tool-box" @click="addFriend">
					<view class="tool-box-img">
						<image :src="require('@/static/img/main/message/02.svg')"></image>
					</view>
					<view class="tool-box-text"><text>添加好友</text></view>
				</view>
				<view class="tool-box" @click="createGroup">
					<view class="tool-box-img">
						<image :src="require('@/static/img/main/message/03.svg')"></image>
					</view>
					<view class="tool-box-text"><text>创建群聊</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import messageLoading from './message-loading.vue'
	
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex'

	export default {
		props: {
			isShowTool: {
				type: Boolean,
				default: false
			},
			loadingning: {
				type: Boolean,
				default: false
			}
		},
		components: {
			messageLoading
		},
		data() {
			return {
				toolImg: require('@/static/img/main/message/01.svg')
			}
		},
		methods: {
			...mapMutations('m_chat', ['emptyAll', 'cleanChatMsg']),
			//1，打开功能框
			showTool() {
				//this.$refs.share.open()
				this.$emit('changeHeadTool', true)
			},
			//2，关闭弹框功能
			closeShowTool() {
				//console.log(123)
				this.$emit('changeHeadTool', false)
			},

			//3，添加好友
			addFriend() {
				return uni.navigateTo({
					url: '/pages/msg/search/search'
				})
			},
			//4，创建群聊
			createGroup() {
				return uni.navigateTo({
					url: '/pages/msg/create-group/create-group'
				})
			},
			//5，清空消息列表
			closeMessage() {
				var that = this
				uni.$isShowModal('清空聊天记录将无法恢复！').then(resultState => {
					if (resultState) {
						that.cleanChatMsg()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.head-con {
		position: fixed;
		z-index: 39;
		top: 0;
		width: 100%;
		height: 50px;
		background-color: #fff;
		padding-top: var(--status-bar-height);
		display: flex;
		justify-content: space-between;

		.left-title {
			display: flex;

			.left-title-text {
				line-height: 50px;

				text {
					font-size: 34rpx;
					font-weight: 600;
					margin-left: 20rpx;
				}
			}

		}

		.right {
			display: flex;
			justify-content: right;

			.right-close {
				width: 80rpx;
				height: 50px;

				text-align: center;

				image {
					width: 21px;
					height: 21px;
					margin-top: 12px;
				}
			}

			.right-tool {
				// position: relative;
				width: 80rpx;
				height: 50px;
				text-align: center;

				image {
					width: 21px;
					height: 21px;
					margin-top: 12px;
				}

			}
		}


	}

	.tool-con {
		position: absolute;
		z-index: 99;
		top: calc(80rpx + var(--status-bar-height));
		right: 20rpx;

		background-color: #666666;
		width: 240rpx;
		height: 220rpx;
		border-radius: 10rpx;
		box-shadow: 4rpx 4rpx 8rpx #888888;

		&::after {
			width: 500rpx;
			height: 500rpx;
			background-color: #888888;
		}
	}

	.tool-box {
		height: 100rpx;
		display: flex;

		&:active {
			background-color: rgba(0, 0, 0, 0.3);
		}

		.tool-box-img {
			image {
				width: 40rpx;
				height: 40rpx;
				margin: 30rpx 10rpx 0 30rpx;
			}
		}

		.tool-box-text {
			line-height: 100rpx;
			color: #fff;
			font-size: 28rpx;
		}
	}


	.head-con-zw {
		width: 100%;
		height: calc(90rpx + var(--status-bar-height));
	}

	.tool-con-bg {
		width: 100%;
		min-height: 100vh;
		// background-color: red;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 39;
		//background-color: red;
	}
</style>